def e(t):
    if t == 1:
        return False
    te = True
    b = t - 1
    while b > 1:
        if not t % b:
            te = False
            break
        b -= 1
    return te
n = input()
reh = []
for i in range(len(n)):
    for a in range(i + 1, len(n) + 1):
        t = int(n[i:a])
        if e(t):
            reh += [t]
print(max(reh) if reh else 0)

